package cn.tedu.boot051.controller;

import cn.tedu.boot051.entity.User;
import cn.tedu.boot051.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired//自动关联(注入)spring中的bean(Java里的所有对象)
    UserMapper mapper;
    @RequestMapping("/reg")//RequestMapping映射web前端请求和后端方法,()中的符号代表浏览器(客户端)
    public int reg(@RequestBody User user){
        User u = mapper.selectByUsername(user.getUsernmae());
        if(u!=null){
            return 2;//用户名已存在
        }
        mapper.insert(user);
        return 1;//注册成功

    }

}


